package javabase.schoolwork.day6_10;

/**
 * @author fance
 * @date 2018/6/10 13:38
 */
class A {
    public synchronized void  say(B b) {
        System.out.println("a to b ");
        b.get();
    }
    public synchronized void get() {
        System.out.println("a get...");
    }
}class B {
    public synchronized void  say(A a) {
        System.out.println("b to a ");
        a.get();
    }
    public synchronized void get() {
        System.out.println("b get...");
    }
}


public class SyncTest implements Runnable{
    private static A a = new A();
    private static B b = new B();

    public SyncTest() {
        new Thread(this).start();
        a.say(b);
    }

    @Override
    public void run() {
        b.say(a);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new SyncTest();
    }
}
